#include "Input.h"

Input::Input(ALLEGRO_EVENT_QUEUE* event_queue):

    _event_queue(event_queue)
{
    _key = { false, false, false, false, false};
}

void Input::wait_for_event()
{
    al_wait_for_event(_event_queue, &_ev);
}

void Input::key_press(bool &finish)
{
    if (_ev.type == ALLEGRO_EVENT_KEY_DOWN)
    {
            switch (_ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_ESCAPE:
                    finish = true;
                    break;

                case ALLEGRO_KEY_UP:
                    _key[UP] = true;
                    break;

                case ALLEGRO_KEY_DOWN:
                    _key[DOWN] = true;
                    break;

                case ALLEGRO_KEY_LEFT:
                    _key[LEFT] = true;
                    break;

                case ALLEGRO_KEY_RIGHT:
                    _key[RIGHT] = true;
                    break;

                case ALLEGRO_KEY_SPACE:
                    _key[SPACE] = true;
                    break;
            }
    }

    else if (_ev.type == ALLEGRO_EVENT_KEY_UP)
    {
            switch (_ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_ESCAPE:
                    finish = true;
                    break;

                case ALLEGRO_KEY_UP:
                    _key[UP] = false;
                    break;

                case ALLEGRO_KEY_DOWN:
                    _key[DOWN] = false;
                    break;

                case ALLEGRO_KEY_LEFT:
                    _key[LEFT] = false;
                    break;

                case ALLEGRO_KEY_RIGHT:
                    _key[RIGHT] = false;
                    break;

                case ALLEGRO_KEY_SPACE:
                    _key[SPACE] = false;
                    break;

            }
    }
}

ALLEGRO_EVENT Input::get_ev()
{
    return _ev;
}

bool Input::get_key(int key)
{
    return _key[key];
}

void Input::set_key(int key, bool button_press)
{
    _key[key] = button_press;
}

Input::~Input()
{

}
